package config

import (
	"github.com/spf13/viper"
	"wechat-push/pkg/logger"
)

var Cfg Config

type Config struct {
	Wechat   Wechat
	Users    []User
	QWeather QWeather
	Quote    Quote
	Cron     Cron
	Template Template
}

// 微信配置
type Wechat struct {
	AppId     string
	AppSecret string
}

// 用户
type User struct {
	Name     string
	Region   string
	City     string
	WechatId string
	IsUsed   bool
}

// 每日一句
type Quote struct {
	QuoteCh string
	QuoteEn string
}

// 和风天气配置
type QWeather struct {
	Key string
}

// 定时任务
type Cron struct {
	Spec string
	On   bool
}

type Template struct {
	Weather string
}

func Init() bool {
	v := viper.New()
	v.SetConfigName("config")
	v.SetConfigType("yml")
	v.AddConfigPath(".")

	err := v.ReadInConfig()
	if err != nil {
		logger.Log.Error("load config err: ", err)
		return false
	}
	err = v.Unmarshal(&Cfg)
	if err != nil {
		logger.Log.Error("unmarshal config err:", err)
		return false
	}
	return true
}
